/*
 * eval.c
 *
 *  Created on: Apr 16, 2013
 *      Author: locpm
 */
#include "extglobals.h"
#include "protos.h"

int eval()
{
	int score;
	int whitePawns, whiteAdvisors, whiteElephants, whiteRooks, whiteCannons, whiteHorses;
	int blackPawns, blackAdvisors, blackElephants, blackRooks, blackCannons, blackHorses;
	int whiteTotal, blackTotal;

	whitePawns = bitCntBB(board.whitePawns);
	whiteAdvisors = bitCntBB(board.whiteAdvisors);
	whiteElephants = bitCntBB(board.whiteElephants);
	whiteRooks = bitCntBB(board.whiteRooks);
	whiteCannons = bitCntBB(board.whiteCannons);
	whiteHorses = bitCntBB(board.whiteHorses);

	blackPawns = bitCntBB(board.blackPawns);
	blackAdvisors = bitCntBB(board.blackAdvisors);
	blackElephants = bitCntBB(board.blackElephants);
	blackRooks = bitCntBB(board.blackRooks);
	blackCannons = bitCntBB(board.blackCannons);
	blackHorses = bitCntBB(board.blackHorses);

	whiteTotal = whitePawns*PAWN_VALUE + whiteAdvisors*ADVISOR_VALUE
			+ whiteElephants*ELEPHANT_VALUE + whiteRooks*ROOK_VALUE
			+ whiteCannons*CANNON_VALUE + whiteHorses*HORSE_VALUE;

	blackTotal = blackPawns*PAWN_VALUE + blackAdvisors*ADVISOR_VALUE
			+ blackElephants*ELEPHANT_VALUE + blackRooks*ROOK_VALUE
			+ blackCannons*CANNON_VALUE + blackHorses*HORSE_VALUE;

	score = whiteTotal - blackTotal;

	if (board.nextMove)
		return -score;
	else
		return score;
}
